/**
 * @author: tengjuyuan
 * @file: Pair.h
 * Pair的简单实现
 */
#pragma once

template <typename T1, typename T2>
struct Pair
{
    typedef T1 first_type;
    typedef T2 second_type;

    T1 first;
    T2 second;

    // 默认构造函数
    Pair()
    : first(T1())
    , second(T2())
    {}

    // 构造函数
    Pair(const T1& t1, const T2& t2)
    : first(t1)
    , second(t2)
    {}

    // 拷贝构造函数
    template <typename U1, typename U2>
    explicit Pair(const Pair<U1, U2>& pair)
    : first(pair.first)
    , second(pair.second)
    {}

    // 赋值构造函数
    template <typename U1, typename U2>
    Pair& operator=(const Pair<U1, U2>& rhs)
    {
        this->first = rhs.first;
        this->second = rhs.second;
        return *this;
    }
};

template <class T1, class T2>
bool operator==(const Pair<T1, T2>& s1, const Pair<T1, T2>& s2)
{
    return (s1.first == s2.first) && (s1.second == s2.second);
}

template <class T1, class T2>
bool operator>(const Pair<T1, T2>& s1, const Pair<T1, T2>& s2)
{
    return (  s1.first > s2.first) 
        || (!(s1.first < s2.first) && s1.second > s2.second);
}

template <class T1, class T2>
bool operator<(const Pair<T1, T2>& s1, const Pair<T1, T2>& s2)
{
    return (  s1.first < s2.first) 
        || (!(s1.first > s2.first) && s1.second < s2.second);
}

template <class T1, class T2>
Pair<T1, T2> make_Pair(const T1& t1, const T2& t2)
{
    return Pair<T1, T2>(t1, t2);
}
